package com.org.cys.controller.base;

import java.util.Date;
import java.util.Map;

import org.apache.log4j.Logger;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.web.servlet.ModelAndView;

import com.org.cys.util.PageData;  
  

/**
 * 测试Controller
 * @author caiyushen
 * */
@Controller  
@RequestMapping("/test")  
public class TestController extends BaseController{  
    
	private static Logger logger = Logger.getLogger(TestController.class);
	
    /**
     * 去测试页面
     * */
    @RequestMapping(value="/goTest",method = RequestMethod.GET)  
    public ModelAndView goTest() throws Exception{  
    	ModelAndView mv = this.getModelAndView();
    	PageData pd = new PageData();
    	pd.put("weclome", "helloWord");
        mv.addObject("pd",pd);
        mv.setViewName("test");
        return mv;  
    }  
    
    /**
     * 去测试页面
     * */
    @RequestMapping(value="/toTest",method = RequestMethod.GET)  
    public String toTest() throws Exception{  
    	ModelAndView mv = this.getModelAndView();
    	PageData pd = new PageData();
    	pd.put("weclome", "helloWord");
        mv.addObject("pd",pd);
        return "test";  
    }  
    
    
	
	/**
	 * 测试Spring MVC返回JSON格式
	 * */
	@ResponseBody
    @RequestMapping(value="/testJSON",method = RequestMethod.GET)
    public PageData testJSON(){
    	PageData pd = new PageData();
    	Long longData = 5620420010329092096L;
    	Date newDate = new Date();
    	pd.put("date", newDate);
    	pd.put("dataStr", newDate.toString());
    	pd.put("long", longData);
    	pd.put("longStr", longData.toString());
    	System.out.println("pd: "+pd.toString());
    	return pd;
    }
	
	
	/**
	 * user的form表单校验
			选择确定 提交后台参数的方式  （form表单提交，jq获取form里面参数方法：$("#fm").serialize()）
			（
			  后台接收参数方式：
				Srping MVC:
					@RequestParam  Map<String,Object> pd  --> contentType:"application/x-www-form-urlencoded;charset=utf-8"
					@RequestBody PageData pd  --> contentType:"application/json"、contentType:"application/x-www-form-urlencoded;charset=utf-8"
				PageData:
					this.getPageData();  --> contentType:"application/x-www-form-urlencoded;charset=utf-8"
			  前台：
					contentType:"application/json"
					contentType:"application/x-www-form-urlencoded;charset=utf-8"
			 ）
	 * 
	 * */
	
	/**
	 * 测试POST方式提交，this.pageData()方法。
	 * */
	@ResponseBody
    @RequestMapping(value="/getJSONData",method = RequestMethod.POST)
    public PageData getJSONData(){
    	PageData pd = new PageData();
    	pd = this.getPageData();
    	System.out.println("pd： "+pd.toString());
    	return pd;
    }
	
	/**
	 * 测试POST方式提交
	 * */
	@ResponseBody
    @RequestMapping(value="/getJSONData2",method = RequestMethod.POST)
    public PageData getJSONData2(@RequestBody PageData pd){
    	System.out.println("pd： "+pd.toString());
    	return pd;
    }
	
	
	/**
	 * 测试POST方式提交
	 * */
	@ResponseBody
    @RequestMapping(value="/getJSONData3",method = RequestMethod.POST)
    public void getJSONData3(@RequestParam Map<String,Object> pd){
    	System.out.println("pd： "+pd.toString());
    }
	
	/**
	 * 测试POST方式提交
	 * */
	@ResponseBody
    @RequestMapping(value="/getJSONData4",method = RequestMethod.POST)
    public PageData getJSONData4(@RequestParam(value="data", required=true)  String data){
    	System.out.println("data： "+data);
    	PageData pd = new PageData();
    	pd.put("data", data);
    	return pd;
    }
	
	/**
	 * 测试POST方式提交
	 * */
	@ResponseBody
    @RequestMapping(value="/getJSONData5",method = RequestMethod.POST)
    public PageData getJSONData5(@RequestParam String data){
    	System.out.println("data： "+data);
    	PageData pd = new PageData();
    	pd.put("data", data);
    	return pd;
    }
}  